import React from 'react'
import {route} from "./type"
import {Switch,Route,Redirect} from "react-router-dom"
interface Props {
    routes:Array<route>
}

const RouterView=({routes}:Props)=>{
    return (
        <Switch>
            {
                routes.map((item,index)=>{
                    if(item.to){
                        return <Redirect to={item.to as string} from={item.from} exact/>
                    }
                    return <Route path={item.path} key={index} render={(routeProps)=>{
                        if(item.children){
                            return <item.component routes={item.children} {...routeProps}/>
                        }
                        return <item.component {...routeProps}/>
                    }}/>
                })
            }
        </Switch>
    )
}
export default  RouterView

